package com.miplus.ccrm.core.service.strategy;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.miplus.ccrm.common.CmdResVo;
import com.miplus.ccrm.core.controller.vo.strategy.ActRuleEditVo;
import com.miplus.ccrm.core.controller.vo.strategy.ActRuleReqVo;
import com.miplus.ccrm.core.controller.vo.strategy.ActRuleResVo;
import com.miplus.ccrm.core.controller.vo.strategy.ActRuleStatusVo;
import com.miplus.ccrm.core.pojo.CfgActivityQuerydatacol;
import com.miplus.ccrm.core.pojo.CfgActivityQuerylink;
import com.miplus.ccrm.core.mapper.CfgActivityQuerylinkMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
* @author pc
* @description 针对表【cfg_activity_querylink(活动清单筛选条件关联表)】的数据库操作Service实现
* @createDate 2024-03-23 14:17:02
*/
@Service
public class CfgActivityQuerylinkServiceImpl extends MPJBaseServiceImpl<CfgActivityQuerylinkMapper, CfgActivityQuerylink>
    implements CfgActivityQuerylinkService{

    @Override
    public IPage<ActRuleResVo> activityRuleList(ActRuleReqVo paras)
    {
        return selectJoinListPage(new Page<>(paras.getPageNum(), paras.getPageSize()),
                ActRuleResVo.class,
                new MPJLambdaWrapper<CfgActivityQuerylink>()
                        .selectAs("(select dsc from sys_names n where n.tid = 'ACTIVITY.QUERY.METHOD' and n.id = t.method)",ActRuleResVo::getMethoddesc)
                        .selectAs("(select coldesc from cfg_activity_querydatacol c2 where splicecol = t.splicecol)",ActRuleResVo::getColdesc)
                        .selectAll(CfgActivityQuerylink.class)
                        .eq("activityid", paras.getActivityid())
                        .eq("type",paras.getType())
                        .orderByAsc("queryruleid")
        );
    }

    @Override
    public CmdResVo activityRuleUpdate(ActRuleEditVo paras)
    {
        CfgActivityQuerylink def=new CfgActivityQuerylink();
        BeanUtils.copyProperties(paras,def);
        def.setQuyid(paras.getQuyid());
        int ret=baseMapper.updateById(def);
        return new CmdResVo(ret,def.getQueryruleid().toString());
    }

    @Override
    public CmdResVo activityRuleInsert(ActRuleEditVo paras)
    {
        CfgActivityQuerylink def=new CfgActivityQuerylink();
        BeanUtils.copyProperties(paras,def);
        def.setQuyid(paras.getQuyid());
        int ret=baseMapper.insert(def);
        return new CmdResVo(ret,def.getQueryruleid().toString());
    }

    @Override
    public CmdResVo activityRuleDelete(int id)
    {
        int ret=baseMapper.deleteById(id);
        return new CmdResVo(ret,Integer.toString(id));
    }

    @Override
    public CmdResVo activityRuleUpStatus(ActRuleStatusVo paras)
    {
        CfgActivityQuerylink def=new CfgActivityQuerylink();
        def.setStatus(paras.getStatus());
        def.setQueryruleid(paras.getQueryruleid());

        int ret=baseMapper.updateById(def);
        return new CmdResVo(ret,def.getQueryruleid().toString());
    }
}




